<?php
/**
 * This view is used by console/controllers/MigrateController.php.
 *
 * The following variables are available in this view:
 */
/* @var $className string the new migration class name without namespace */
/* @var $namespace string the new migration class namespace */

echo "<?php\n";
if (!empty($namespace)) {
    echo "\nnamespace {$namespace};\n";
}
?>

use yii\db\Migration;

/**
 * Class <?= $className . "\n" ?>
 * - Custom Field Example：
 *   'example_field' => Schema::TYPE_STRING . ' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT "" COMMENT "自定义字段配置项示例"',
 *
 * - utf8mb4 下索引字段的varchar类型最大长度是：191
 *   'example_field' => $this->string(191)->notNull()->unique()->comment('This is custom comment'),
 */
class <?= $className ?> extends Migration
{
    const TABLE_NAME = '{{%table_placeholder}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ENGINE=InnoDB COMMENT="table_comment_placeholder"';
        }

        $this->createTable(self::TABLE_NAME, [
            'id' => $this->primaryKey()->comment('ID'),

            'created_at' => $this->dateTime()->notNull()->comment('创建日期'),
            'updated_at' => $this->dateTime()->defaultValue(null)->comment('上次更新'),
        ], $tableOptions);

        //$this->createIndex('idx_field', self::TABLE_NAME, ['field']);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
